package com.backedserver.controller.departmentjob;

import com.common.base.BindCreateBy;
import com.common.base.BindUpdateBy;
import com.common.requestvo.departmentjob.DepartmentReqVo;
import com.common.service.departmentjob.DepartmentService;
import com.common.utils.PageUtil;
import com.common.utils.ResultVoUtil;
import com.common.vo.PageVo;
import com.common.vo.ResultVo;
import com.common.vo.departmentjob.DepartmentVo;
import com.common.vo.judicialpersonal.JudicialPersonalVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * 部门Controller
 *
 * @author johnny
 * @create 2021-05-14 8:51 下午
 **/
@Api(tags = "部门模块")
@RestController
@RequestMapping("/department")
@Slf4j
public class DepartmentController {

    private final DepartmentService departmentService;

    public DepartmentController(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @GetMapping("/listByCondition")
    @ApiOperation(value = "根据条件查询部门列表 (分页)", notes = "可以作为 个人档案管理列表页面 查询列表")
    public ResultVo listByCondition(DepartmentReqVo departmentReqVo,
                                    PageVo pageVo) {
        pageVo.setPageNumber(pageVo.getPageNumber() - 1);
        Page<DepartmentVo> page = departmentService.listByCondition(departmentReqVo, PageUtil.initPage(pageVo));
        return ResultVoUtil.success(page);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增部门信息")
    @BindCreateBy
    public ResultVo add(@RequestBody DepartmentReqVo departmentReqVo) {
        departmentService.add(departmentReqVo);
        return ResultVoUtil.success();
    }

    @PostMapping("/edit")
    @ApiOperation(value = "修改部门信息")
    @BindUpdateBy
    public ResultVo edit(@RequestBody DepartmentReqVo departmentReqVo) {
        departmentService.edit(departmentReqVo);
        return ResultVoUtil.success();
    }

    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除部门信息")
    @ApiImplicitParam(name = "id", value = "部门id", dataType = "Long", example = "1")
    public ResultVo delete(@PathVariable Long id) {
        departmentService.delete(id);
        return ResultVoUtil.success();
    }


}